﻿// Control20Dlg_1.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "Control20Dlg_1.h"
#include "afxdialogex.h"


// CControl20Dlg_1 对话框

IMPLEMENT_DYNAMIC(CControl20Dlg_1, CDialogEx)

CControl20Dlg_1::CControl20Dlg_1(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_CONTROL_20, pParent)
{

}

CControl20Dlg_1::~CControl20Dlg_1()
{
}

void CControl20Dlg_1::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, m_combPosNo);
	DDX_Control(pDX, IDC_EDIT1, m_editStep);
	DDX_Control(pDX, IDC_EDIT2, m_editX);
	DDX_Control(pDX, IDC_EDIT3, m_editY);
	DDX_Control(pDX, IDC_EDIT4, m_editZ);
}


BEGIN_MESSAGE_MAP(CControl20Dlg_1, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON10, &CControl20Dlg_1::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON6, &CControl20Dlg_1::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON2, &CControl20Dlg_1::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CControl20Dlg_1::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CControl20Dlg_1::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CControl20Dlg_1::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON26, &CControl20Dlg_1::OnBnClickedButton26)
	ON_BN_CLICKED(IDC_BUTTON27, &CControl20Dlg_1::OnBnClickedButton27)
	ON_BN_CLICKED(IDC_BUTTON28, &CControl20Dlg_1::OnBnClickedButton28)
	ON_BN_CLICKED(IDC_BUTTON29, &CControl20Dlg_1::OnBnClickedButton29)
	ON_BN_CLICKED(IDC_BUTTON30, &CControl20Dlg_1::OnBnClickedButton30)
	ON_BN_CLICKED(IDC_BUTTON7, &CControl20Dlg_1::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON24, &CControl20Dlg_1::OnBnClickedButton24)
	ON_BN_CLICKED(IDC_BUTTON25, &CControl20Dlg_1::OnBnClickedButton25)
	ON_BN_CLICKED(IDC_BUTTON8, &CControl20Dlg_1::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CControl20Dlg_1::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON12, &CControl20Dlg_1::OnBnClickedButton12)
	ON_BN_CLICKED(IDC_BUTTON23, &CControl20Dlg_1::OnBnClickedButton23)
	ON_BN_CLICKED(IDC_BUTTON1, &CControl20Dlg_1::OnBnClickedButton1)
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CControl20Dlg_1 消息处理程序


void CControl20Dlg_1::OnCancel()
{
	KillTimer(TIMER_ID_AXIS_STATUS_1);
	CDialogEx::OnCancel();
}


BOOL CControl20Dlg_1::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_combPosNo.ResetContent();
	m_combPosNo.AddString(L"0:待机位");
	m_combPosNo.AddString(L"1:取螺丝位置");
	m_combPosNo.AddString(L"2:打螺丝位置 1");
	m_combPosNo.AddString(L"3:打螺丝位置 2");
	m_combPosNo.AddString(L"4:打螺丝位置 3");
	m_combPosNo.AddString(L"5:打螺丝位置 4");
	m_combPosNo.AddString(L"6:打螺丝位置 5");
	m_combPosNo.AddString(L"7:打螺丝位置 6");
	m_combPosNo.AddString(L"8:吐螺丝位置");
	m_combPosNo.SetCurSel(0);
	SetTimer(TIMER_ID_AXIS_STATUS_1, 500, NULL);
	return TRUE;
}


void CControl20Dlg_1::OnBnClickedButton10()
{
	if (gSystemMgr.Y47 == OFF) {
		gSystemMgr.m_cIo.SetOutputIo(47, ON);
	}
	else {
		gSystemMgr.m_cIo.SetOutputIo(47, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedButton6()
{
	if (gSystemMgr.Y20 == OFF) {
		gSystemMgr.m_cIo.SetOutputIo(20, ON);
	}
	else {
		gSystemMgr.m_cIo.SetOutputIo(20, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedButton2()
{
	gSystemMgr.m_cIo.SetOutputIo(23, ON);
	gSystemMgr.m_cIo.SetOutputIo(24, OFF);
}


void CControl20Dlg_1::OnBnClickedButton3()
{
	gSystemMgr.m_cIo.SetOutputIo(24, ON);
	gSystemMgr.m_cIo.SetOutputIo(23, OFF);
}


void CControl20Dlg_1::OnBnClickedButton4()
{
	gSystemMgr.m_cIo.SetOutputIo(21, ON);
	gSystemMgr.m_cIo.SetOutputIo(22, OFF);
}


void CControl20Dlg_1::OnBnClickedButton5()
{
	gSystemMgr.m_cIo.SetOutputIo(22, ON);
	gSystemMgr.m_cIo.SetOutputIo(21, OFF);
}


void CControl20Dlg_1::OnBnClickedButton26()
{
	gSystemMgr.m_cIo.SetOutputIo(30, ON);
	Sleep(200);
	gSystemMgr.m_cIo.SetOutputIo(30, OFF);
}


void CControl20Dlg_1::OnBnClickedButton27()
{
	gSystemMgr.m_cIo.SetOutputIo(31, ON);
	Sleep(200);
	gSystemMgr.m_cIo.SetOutputIo(31, OFF);
}


void CControl20Dlg_1::OnBnClickedButton28()
{
	gSystemMgr.m_cIo.SetOutputIo(32, ON);
	Sleep(200);
	gSystemMgr.m_cIo.SetOutputIo(32, OFF);
}


void CControl20Dlg_1::OnBnClickedButton29()
{
	if (gSystemMgr.Y51 == OFF) {
		gSystemMgr.m_cIo.SetOutputIo(51, ON);
	}
	else {
		gSystemMgr.m_cIo.SetOutputIo(51, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedButton30()
{
	if (gSystemMgr.Y50 == OFF) {
		gSystemMgr.m_cIo.SetOutputIo(50, ON);
	}
	else {
		gSystemMgr.m_cIo.SetOutputIo(50, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedButton7()
{
	//if (gSystemMgr.m_bMotorErrorFlag || !gSystemMgr.m_bHomeFlag)
	//	return;
	int n;
	n = m_combPosNo.GetCurSel();
	gSystemMgr.m_nButtonValue = 200 + n;
}


void CControl20Dlg_1::OnBnClickedButton24()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton25()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton8()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton9()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton12()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton23()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton1()
{
	gSystemMgr.m_vCMotor[MOTOR_X].StopMove();
	gSystemMgr.m_vCMotor[MOTOR_Y].StopMove();
	gSystemMgr.m_vCMotor[MOTOR_Z].StopMove();
}


void CControl20Dlg_1::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == TIMER_ID_AXIS_STATUS_1)
	{
		double nDis = gSystemMgr.m_vCMotor[MOTOR_X].m_nCurPositon;
		CString cstr;
		cstr.Format(L"%.1f", nDis);
		m_editX.SetWindowTextW(cstr);
		nDis = gSystemMgr.m_vCMotor[MOTOR_Y].m_nCurPositon;
		cstr.Format(L"%.1f", nDis);
		m_editY.SetWindowTextW(cstr);
		nDis = gSystemMgr.m_vCMotor[MOTOR_Z].m_nCurPositon;
		cstr.Format(L"%.1f", nDis);
		m_editZ.SetWindowTextW(cstr);
	}
	CDialogEx::OnTimer(nIDEvent);
}
